﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controller;
using Model.User;
using Model.Course;

public partial class CourseView_CreateTaskView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    // Important! The text of content Text Box can have some dangerous HTML/JS scripts! 
    // There is need to add some security checking in here.
    protected void addTaskToolbarButton_Click(object sender, ImageClickEventArgs e)
    {
        if (!nameTextBox.Text.Equals(""))
        {
            DateTime start = DateTime.ParseExact(startDateTextBox.Text, "yyyy-MM-dd", null);
            DateTime end = DateTime.ParseExact(endDateTextBox.Text, "yyyy-MM-dd", null);

            Task c = TaskController.createTask(Convert.ToInt32(Session["CourseId"]),
                                                       nameTextBox.Text, start, end, contentTextBox.Text, null);

            if (c == null)
                errorLabel.Visible = true;
            else
            {
                Session["ActiveMenuButton"] = "menuButton7";
                Response.Redirect("~/CourseView/ViewCourseTasks.aspx");
            }
        }
    }
}